home *** CD-ROM | disk | FTP | other *** search
/ PC Open 100 / PC Open 100 CD 1.bin / CD1 / INTERNET / EMAIL / pop file / setup.exe / insert.pl < prev    next >
Encoding:
Perl Script  |  2004-02-02  |  3.2 KB  |  120 lines

  1. #!/usr/bin/perl
  2. # ---------------------------------------------------------------------------------------------
  3. #
  4. # insert.pl --- Inserts a mail message into a specific bucket
  5. #
  6. # Copyright (c) 2001-2003 John Graham-Cumming
  7. #
  8. #   This file is part of POPFile
  9. #
  10. #   POPFile is free software; you can redistribute it and/or modify
  11. #   it under the terms of the GNU General Public License as published by
  12. #   the Free Software Foundation; either version 2 of the License, or
  13. #   (at your option) any later version.
  14. #
  15. #   POPFile is distributed in the hope that it will be useful,
  16. #   but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18. #   GNU General Public License for more details.
  19. #
  20. #   You should have received a copy of the GNU General Public License
  21. #   along with POPFile; if not, write to the Free Software
  22. #   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. #
  24. # ---------------------------------------------------------------------------------------------
  25.  
  26. use strict;
  27. use Classifier::Bayes;
  28. use Classifier::WordMangle;
  29. use POPFile::Configuration;
  30. use POPFile::MQ;
  31. use POPFile::Logger;
  32.  
  33. my $code = 0;
  34.  
  35. if ( $#ARGV > 0 ) {
  36.     my $c = new POPFile::Configuration;
  37.     my $mq = new POPFile::MQ;
  38.     my $l = new POPFile::Logger;
  39.     my $b = new Classifier::Bayes;
  40.     my $w = new Classifier::WordMangle;
  41.  
  42.     $c->configuration( $c );
  43.     $c->mq( $mq );
  44.     $c->logger( $l );
  45.  
  46.     $c->initialize();
  47.  
  48.     $l->configuration( $c );
  49.     $l->mq( $mq );
  50.     $l->logger( $l );
  51.  
  52.     $l->initialize();
  53.  
  54.     $w->configuration( $c );
  55.     $w->mq( $mq );
  56.     $w->logger( $l );
  57.  
  58.     $w->start();
  59.  
  60.     $mq->configuration( $c );
  61.     $mq->mq( $mq );
  62.     $mq->logger( $l );
  63.  
  64.     $b->configuration( $c );
  65.     $b->mq( $mq );
  66.     $b->logger( $l );
  67.  
  68.     $b->{parser__}->mangle( $w );
  69.     $b->initialize();
  70.  
  71.     $c->load_configuration();
  72.  
  73.     $b->start();
  74.     my $session = $b->get_session_key( 'admin', '' );
  75.  
  76.     my @files;
  77.  
  78.     if ($^O =~ /linux/) {
  79.         @files = @ARGV[1 .. $#ARGV];
  80.     } else {
  81.         @files = map { glob } @ARGV[1 .. $#ARGV];
  82.     }
  83.  
  84.     # Check for the existence of each file first because the API
  85.     # call we use does not care if a file is missing
  86.  
  87.     foreach my $file (@files) {
  88.         if ( !(-e $file) ) {
  89.             print STDERR "Error: File `$file' does not exist, insert aborted.\n";
  90.             $code = 1;
  91.             last;
  92.         }
  93.     }
  94.  
  95.     if ( $code == 0 ) {
  96.         if ( !$b->is_bucket( $session, $ARGV[0] ) ) {
  97.             print STDERR "Error: Bucket `$ARGV[0]' does not exist, insert aborted.\n";
  98.             $code = 1;
  99.         } else {
  100.             $b->add_messages_to_bucket( $session, $ARGV[0], @files );
  101.             print "Added ", $#files+1, " files to `$ARGV[0]'\n";
  102.         }
  103.     }
  104.  
  105.     $b->release_session_key( $session );
  106.     $b->stop();
  107.     $l->stop();
  108.     $mq->stop();
  109.     $c->stop();
  110. } else {
  111.     print "insert.pl - insert mail messages into a specific bucket\n\n";
  112.     print "Usage: insert.pl <bucket> <messages>\n";
  113.     print "       <bucket>           The name of the bucket\n";
  114.     print "       <messages>         Filename of message(s) to insert\n";
  115.     $code = 1;
  116. }
  117.  
  118. exit $code;
  119.  
  120.